package com.clientes;

import java.util.List;

import com.eventos.LugarOverlay;
import com.eventssmartphone.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;


public class ActivityVerAmbiente extends MapActivity implements OnClickListener {
	private MapView mapView;
	private TextView nombreAmbiente;
	private TextView direccion;
	private TextView estacionamientos;
	List<Overlay> mapOverlays;
	LugarOverlay itemizedoverlay;
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 * super.onCreate(savedInstanceState);
		setContentView(R.layout.cl_listaambientes);
		
		lista = (ListView) findViewById(R.id.listaAmbientes);
		
		List<AmbienteBean> listaAmbientes = GestorAmbiente.getInstance().dameAmbientesJson();
		AmbienteAdapter adapter = new AmbienteAdapter(listaAmbientes, this);
		lista.setAdapter(adapter);
		lista.setOnItemClickListener(this);
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cl_itemambiente);
		Bundle b = getIntent().getExtras();
		// TODO Put your code here
		Log.i("nombre", "Activitu ver ambiente ");
		Log.i("nombre", b.getString("nombre") +"2");
		nombreAmbiente = (TextView)findViewById(R.id.nombreAmbiente);
		nombreAmbiente.setText(b.getString("nombre"));		
		direccion = (TextView)findViewById(R.id.direccionAmbiente);
		direccion.setText(b.getString("direccion"));
		Log.i("nombre", b.getString("nombre") +"3");
		estacionamientos = (TextView)findViewById(R.id.estacionamientoAmbiente);
		if (b.getInt("estacionamientos") == 0)
			estacionamientos.setText("No hay estacionamientos disponibles");
		else
			estacionamientos.setText("Hay estacionamientos disponibles");
		//Log.i("nombre", b.getString("nombre") +"4");
		
		mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		
		 mapOverlays = mapView.getOverlays();
	     Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
	     itemizedoverlay = new LugarOverlay(drawable, this);
	     Log.i("ss", "mapa"+(int)(b.getDouble("latitud")*1e6));
	     GeoPoint point = new GeoPoint((int)(b.getDouble("latitud")*1e6),(int)(b.getDouble("longitud")*1e6));
	    OverlayItem overlayitem = new OverlayItem(point, b.getString("nombre"), b.getString("direccion"));
	                
	        itemizedoverlay.addOverlay(overlayitem);
	        mapOverlays.add(itemizedoverlay);
	        
	        mapOverlays.size();
	        mapView.getController().setCenter(point);
	        mapView.getController().setZoom(15);
	     // Acquire a reference to the system Location Manager
	        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
	        
	        
	     // Define a listener that responds to location updates
	        LocationListener locationListener = new LocationListener() {
	            
	        	public void onLocationChanged(Location location) {
	        		GeoPoint point = new GeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6));
	        		OverlayItem overlayitem = new OverlayItem(point, "AQUI", "ESTAS TU");
	                
	                itemizedoverlay.addOverlay(overlayitem);
	                mapOverlays.add(itemizedoverlay);
	        	}

	            public void onStatusChanged(String provider, int status, Bundle extras) {}

	            public void onProviderEnabled(String provider) {}

	            public void onProviderDisabled(String provider) {}
	        };
	        
	        
	        String locationProvider = LocationManager.NETWORK_PROVIDER;
	        
	     // Register the listener with the Location Manager to receive location updates
	        locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);
	          
	        Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
	        
	     // Remove the listener you previously added
	        //locationManager.removeUpdates(locationListener);
	        

	}
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
		}
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}
}